'use strict';

const conn = require('../../libs/Conn');

module.exports = async function (params) {
    let querySql = `SELECT * FROM engineering_progress_file WHERE engineering_id = '${params.engineering_id}';
                    SELECT
                            foundation_test_tanks,
                            material_check_a,
                            foundation_test,
                            important_part_acceptance,
                            first_conversion_reinforcement,
                            material_check_b,
                            standard_reinforcement,
                            top_reinforcement,
                            quality_sampling,
                            concrete_structure,
                            material_check_c,
                            main_structure,
                            other_projects,
                            completion_initial_inspection,
                            completion_acceptance
                FROM
                    engineering_progress_file
                WHERE
                    engineering_id = '${params.engineering_id}';`;
    let rec = await conn(querySql);
    let num = 0 ;
    for(let data in rec[1][0]){
        if(data === 'completion_acceptance'){
            if(rec[1][0][data] === 2){
                num++
            }
        }else{
            if(rec[1][0][data] === 3){
                num++
            }
        }
    }
    let percentage =Math.round(num/15*100);
    return {success: true, data: rec[0][0],percentage:percentage};

};